<h3 id="comments" {% if not entry.comments.count%} style="display:none"{%endif%}>
{{entry.comments.count}} Responses to &#8220;{{entry.title|escape}}&#8221; </h3>

	<ol id="commentlist" class="commentlist">

	{% for comment in entry.comments %}

		<li class="{%cycle alt1,alt %}" id="comment-{{comment.key.id}}">
			<div class="gravatar"><img height="50" width="50" class="avatar avatar-50" src="{{comment.gravatar_url}}" alt=""/></div>
     <div class="comments">
     				{%if comment.weburl %}
			<a href="{{comment.weburl}}" target="_blank">{{comment.author}}</a>
			{% else %}{{comment.author}}{%endif%}
			 On <small class="commentmetadata"><a href="#comment-{{comment.key.id}}" title="">{{comment.date|datetz:"Y-m-d"}} at {{comment.date|datetz:"H:i"}}</a> </small>

			<br />

			<p>{{comment.content}}</p>

			</div>
			<div style="clear:both"></div>


		</li>

	{% endfor %}

	</ol>



<h3 id="respond">Leave a Reply</h3>
<div class="info" id="comment_info"></div>
<form action="/post_comment" method="post" id="commentform"
    class="reply">

<div id="comment_area">
<p><input type="text" name="author" id="author"  size="25"
tabindex="1" class="text" />
<label for="author"><small>Name (required) <span
            style='color:red'>*</span></small></label></p>

<p><input type="text" name="email" id="email"  size="25" tabindex="2"
class="text" />
<label for="email"><small>Mail (will not be published)(required)<span
            style='color:red'>*</span></small></label></p>

<p><input type="text" name="url" id="url"  size="25" tabindex="3"
class="text" />
<label for="url"><small>Website</small></label></p>


<p id="checkarea"><small>Please calculate <span style="color:#D50000"
        id="disp_check">{{checknum1}}+{{checknum2}}</span></small>
<input type="hidden" name="checknum" id="checknum" value="{{checknum1}}+{{checknum2}}" />
<input type="text" name="checkret" id="checkret" value="" size="5"
tabindex="4" class="text" style="width:60px;" />
</p>

</div>

<p><textarea name="comment" id="comment" style="width:96%"  rows="10" tabindex="4"></textarea></p>

<p><input name="submit" type="submit" id="submit" tabindex="5" value=" "  class="comm_submit" onmousedown="this.className='comm_submit_down'" onmousemove="this.className='comm_submit_move'" onmouseout="this.className='comm_submit'"/>
<div id="s_msg" style="display:none;color:red">正在提交留言...</div>
<input type="hidden" name="key" value="{{entry.key}}" />
<input type="hidden" name="useajax" value="1" />
</p>
</form>

 <script>
       loadjs=false;

       commentuser=$.cookie('comment_user');
       if (commentuser)
       {
         [user,email,url]=commentuser.split('#@#');
         $('#author').val(user);
         $('#email').val(email);
         $('#url').val(url);
         $('#checkarea').hide();
       }
       else
       {
       	num1=Math.round(Math.random()*10);
       	num2=Math.round(Math.random()*10);
       	$('#checkarea #checknum').val(num1+'+'+num2);
       	$('#checkarea #disp_check').text(num1+'+'+num2+'=');
       	$('#checkarea').show();
       }

       function showinfo(msg)
       {
       	  alert(msg);
       }
       function add_comment(msg)
       {
       	  comment=$(msg)
       	  if (!loadjs)
       	  {
       	  	$("#commentlist").append(comment).show();
       	  	$.getScript("/static/js/jquery.color.js", function(){
       	  		 comment.animate( { backgroundColor: '#fbc7c7' }, "slow")
       						.animate( { backgroundColor: 'white' }, "slow")
							loadjs=true;
						});
       	  }else
       	  {
       	  	$("#commentlist").append(comment);
       	  	  comment.animate( { backgroundColor: '#fbc7c7' }, "slow")
       						.animate( { backgroundColor: 'white' }, "slow")

       	  }
       }

              $('#commentform').ajaxForm({
              	type:'post',
              	dataType:  'json',
              	beforeSubmit:function(formData,jqForm,options){
              		   var form = jqForm[0];
              		   if (form.author)
              		   {

	              			 if (!form.author.value)
		              		 {
		              		  showinfo('请输入你的名字!');
		              		  form.author.focus();
		              		  return false;
		              		 }
		              		 if (!form.email.value)
		              		 {
		              		 	showinfo('请输入邮件地址');
		              		 	form.email.focus();
		              		 	return false;
		              		 }
           		       }
           		        if ($('#checkarea').css('display')!='none')
								       {
							             if(eval(form.checknum.value)!=form.checkret.value)
							             {
							               alert('计算错误，这个算术好像在幼儿园学过的吧？');
							               form.checkret.value='';
							               form.checkret.focus();
							               return false;
							             }

							           }

                  		 if (!form.comment.value)
                  		 {
                  		 	showinfo('请输入留言内容');
                  		 	form.comment.focus();
                  		 	return false;
                  		 }

                  		 $('#s_msg').text('正在提交留言...').show();

	              		 return true;

              		},
              	success:function(data){
              		  if (data[0])
              		  {
              		  	/*document.cookie=data[2];*/
              		  	add_comment(data[1]);
            		  	$('#s_msg').text('留言提交成功！');
              		  	$('#comment').val('');
              		  }
              		  else
              		  {  if (data[1]==-102)
              		  	 showinfo('计算错误，回幼儿园进修一下再来过。');
              		  	 $('#s_msg').text('留言提交失败！');
              		  	 $('#checkret').focus();

              		  }
              		}
              });

</script>

